Ext.define('AgenteNET.<?php echo $this->package;?>.Store',{
    extend:'Ext.data.Store',
    storeId:'<?php echo $this->modelName;?>Store',
    autoLoad:true,
    autoSync:true,
    //fields:['id','nome','login','email'],
    fields:<?php echo Application_Model_Extjs::getStoreFields($this->model);?>,
    
    proxy: {
        api:{
            create  : '/agentenet/public/Utilitarios/Data/Model/<?php echo $this->modelName;?>/method/post',
            read    : '/agentenet/public/Utilitarios/Data/Model/<?php echo $this->modelName;?>/method/get/id/',
            update  : '/agentenet/public/Utilitarios/Data/Model/<?php echo $this->modelName;?>/method/put/id/',
            destroy : '/agentenet/public/Utilitarios/Data/Model/<?php echo $this->modelName;?>/method/delete/id/'
        },
        type:'rest',
        reader:{
            type:'json',
            root:'data'
        }
    }
});

Ext.define('AgenteNET.<?php echo $this->package;?>.View.List',{
    extend:'Ext.grid.Panel',
    title:'Controle de papeis de usuario do sistema',
    store: Ext.create('AgenteNET.<?php echo $this->package;?>.Store'),
    columns: <?php echo Application_Model_Extjs::getGridColumns($this->model,array('nome','login','email','situacao'));?>,
    dockedItems: [{
        xtype: 'pagingtoolbar',
        store: Ext.data.StoreManager.lookup('<?php echo $this->modelName;?>Store'),
        dock: 'bottom',
        displayInfo: true,
        items:[{
            xtype:'button',
            text:'Novo',
            handler:function(){
               var view=Ext.getCmp('ViewLayer');
               view.remove(1);
               view.add(Ext.create('AgenteNET.<?php echo $this->package;?>.View.Create',{
                        frame:true,
                        region:'south',
                        margins: '5 0 0 0',
               }));
            }
        }]
    }],
    listeners: {
        added: function(){ 
         var menu=Ext.getCmp('ActionLayer');
         menu.removeAll();
         menu.add(Ext.create('AgenteNET.Utilitarios.Menu.View.Options'));
        },
        select: function(el,model){ 
         var view=Ext.getCmp('ViewLayer');
         view.remove(1);
         var form=Ext.create('AgenteNET.<?php echo $this->package;?>.View.Edit',{
                frame:true,
                region:'south',
                margins: '5 0 0 0',
         });
         form.loadRecord(model);
         view.add(form);
        },
        itemClick: function(el,model){ 
         var view=Ext.getCmp('ViewLayer');
         view.remove(1);
         var form=Ext.create('AgenteNET.<?php echo $this->package;?>.View.Edit',{
                frame:true,
                region:'south',
                margins: '5 0 0 0',
         });
         form.loadRecord(model);
         view.add(form);
        },
    },
});

Ext.define('AgenteNET.<?php echo $this->package;?>.View.Create',{
    extend:'Ext.form.Panel',
    title:'Criando novo papel',
    layout:'fit',
    bodyPadding: 5,
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },
    defaultType: 'textfield',
    items: <?php echo Application_Model_Extjs::getFormInputs($this->model,array('nome','login','email','situacao'));?>,
    buttons:[{
        text:'Incluir',
        handler:function(el){
            var <?php echo $this->modelName;?>Store=Ext.data.StoreManager.lookup('<?php echo $this->modelName;?>Store')
            <?php echo $this->modelName;?>Store.add(el.up('form').getValues());
        
            var menu=Ext.getCmp('ViewLayer');
            menu.remove(1);
        }
    },{
        text:'Fechar',
        handler:function(){
            var menu=Ext.getCmp('ViewLayer');
            menu.remove(1);
        }
    }]
});
Ext.define('AgenteNET.<?php echo $this->package;?>.View.Edit',{
        extend:'AgenteNET.<?php echo $this->package;?>.View.Create',
        title:'Editando papel',
    buttons:[{
        text:'Salvar',
        handler:function(el){
            var model=el.up('form').getRecord();
            model.set(el.up('form').getValues());
            
            var view=Ext.getCmp('ViewLayer');
            view.remove(1);
        }
    },{
        text:'Excluir',
        handler:function(el){
            var store=Ext.data.StoreManager.lookup('<?php echo $this->modelName;?>Store')
            store.remove(el.up('form').getRecord());
            
            var view=Ext.getCmp('ViewLayer');
            view.remove(1);
        }
    },{
        text:'Fechar',
        handler:function(){
            var view=Ext.getCmp('ViewLayer');
            view.remove(1);
        }
    }]
});
